package com.inviteOrder.dao;

import com.inviteOrder.domain.Reward;
import lombok.Builder;
import lombok.Data;

import java.util.concurrent.ThreadLocalRandom;

import static com.inviteOrder.strategy.RewardStrategyContext.NEW_USER;
import static com.inviteOrder.strategy.RewardStrategyContext.OLD_USER;

/**
 * @author 大忽悠
 * @create 2022/10/17 10:16
 */
@Data
@Builder
public class User {
    /**
     * 新老用户标识
     */
    private String type;

    public static void getReward(Reward rewardMoney, Long uid) {
        if(uid==50){
            throw new IllegalArgumentException("我是bug");
        }
        StringBuilder sb=new StringBuilder();
        sb.append("当前用户id为: ").append(uid)
                .append(" 奖励的序列号为: ")
                .append(rewardMoney.getId())
                .append(" 奖励的类型为: ")
                .append(rewardMoney.getType().getDescription()).append(" 奖励的金额为: ").append(rewardMoney.getAmount());
        System.out.println(sb.toString());
    }

    /**
     * @param uid
     * @return 返回当前用户邀请用户个数
     */
    public static Integer getInviteNum(Long uid) {
            return ThreadLocalRandom.current().nextInt(10);
    }

    public static User getUser(Long uid) {
        return uid>=100?User.builder().type(NEW_USER).build():User.builder().type(OLD_USER).build();
    }
}
